<template>
  <div class="app-container bg-gray">
    <transition name="fade-transform" mode="out-in">
      <router-view />
    </transition>
    <el-card v-if="isShow" class="box-1">
      <div class="header">
        <div class="bar">
          <el-select v-model="searchTerms.source" placeholder="来源" class="select" clearable @change="getData">
            <el-option v-for="item in sourceList" :key="item.id" :label="item.source_name" :value="item.source_name" />
          </el-select>
          <el-select v-model="searchTerms.cust_state" placeholder="状态" class="select" clearable @change="getData">
            <el-option :value="1" label="已激活"/>
            <el-option :value="0" label="未激活"/>
          </el-select>
          <el-select v-model="searchTerms.recommend" placeholder="指派人" class="select" filterable clearable @change="getData">
            <el-option-group
              v-for="group in allMemberList"
              :key="group.label"
              :label="group.label">
              <el-option
                v-for="item in group['personnel']"
                :key="item.id"
                :label="item.name"
                :value="item.id"/>
            </el-option-group>
          </el-select>
          <el-select v-model="searchTerms.progress" placeholder="跟进状态" class="select" clearable @change="getData">
            <el-option v-for="item in progressList" :key="item" :label="item" :value="item" />
          </el-select>
          <el-select v-model="searchTerms.contact_status" placeholder="逾期 | 未联系" class="select" clearable @change="getData">
            <el-option value="逾期" label="逾期"/>
            <el-option value="未联系" label="未联系"/>
            <el-option value="即将逾期" label="即将逾期"/>
          </el-select>
          <el-tooltip content="注册时间" placement="top">
            <el-date-picker
              v-model="searchTerms.date1"
              class="picker"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd"
              @change="getData"/>
          </el-tooltip>
          <el-tooltip content="下次联系时间" placement="top">
            <el-date-picker
              v-model="searchTerms.date2"
              class="picker"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd"
              @change="getData"/>
          </el-tooltip>
          <el-input v-model="searchTerms.searchValue" placeholder="请输入内容" class="search-input" @change="getData">
            <template slot="prepend">
              <el-select v-model="searchTerms.searchKey" placeholder="请选择" style="width: 110px;" @change="getData">
                <el-option label="手机号码" value="mobile"/>
                <el-option label="昵称" value="name"/>
                <el-option label="客户姓名" value="realname"/>
                <el-option label="微信" value="wechat"/>
                <el-option label="腾讯云ID" value="qq"/>
                <el-option label="公司" value="company"/>
                <el-option label="备注" value="remarks"/>
              </el-select>
            </template>
          </el-input>
          <el-button type="success" class="do-btn" icon="el-icon-search" @click="getData">搜索</el-button>
        </div>
        <div>
          <el-button v-if="queryMatch(80)" type="success" class="bg-green" icon="el-icon-plus" @click="toModify('新增客户')">新增客户</el-button>
          <el-button v-if="queryMatch(107)" type="info" icon="el-icon-tickets"><a :href="modelUrl" target="_blank">下载导入模板</a></el-button>
          <el-upload
            ref="upload"
            :limit="1"
            :show-file-list="false"
            :http-request="uploadFiles"
            :before-upload="beforeUpload"
            class="upload"
            accept=".xls,.xlsx"
            action="">
            <el-button v-if="queryMatch(107)" :loading="uploadLoading" type="primary" icon="el-icon-printer">批量导入</el-button>
          </el-upload>
          <el-button v-if="queryMatch(107)" :loading="downloadLoading" :disabled="downloadLoading" type="primary" icon="el-icon-printer" @click="handleDownload">批量导出</el-button>
          <el-button v-if="queryMatch(102)" type="danger" icon="el-icon-share" @click="toTransfer(1)">批量指派</el-button>
          <el-button v-if="queryMatch(102)" type="danger" icon="el-icon-delete" @click="toDeleteMore">批量删除</el-button>
          <el-button type="primary" icon="el-icon-delete" @click="toSeleteOverdue">即将逾期</el-button>
          <!--<el-button type="danger" icon="el-icon-share" @click="toTransfer(0)">批量转移</el-button>-->
          <el-button type="warning" @click="doClearList">数据过滤</el-button>
          <el-button v-if="queryMatch(266)" type="warning" icon="el-icon-plus" @click="toTransfer2(1)">协助者</el-button>
          <el-button type="warning" @click="dialogVisible3=true">加入分组</el-button>
        </div>
      </div>
      <div class="tag-box">
        <el-tag type="info">我的分组</el-tag>
        <el-tag :effect="searchTerms.group_id===''?'dark':'light'" style="cursor: pointer;" @click="searchTerms.group_id='',getData()">全部</el-tag>
        <el-tag
          v-for="(tag, tagIdx) in groupList"
          :key="tagIdx"
          :effect="searchTerms.group_id===tag.id?'dark':'light'"
          closable
          style="cursor: pointer;"
          @click="searchTerms.group_id=tag.id,getData()"
          @close="handleClose(tag)">{{ tag.name }}</el-tag>
        <el-input v-if="inputVisible" ref="saveTagInput" v-model="inputValue" class="input-new-tag" size="small" @keyup.enter.native="handleInputConfirm" @blur="handleInputConfirm"/>
        <el-button v-else class="button-new-tag" size="small" @click="showInput">+ 新分组</el-button>
      </div>
      <el-table
        v-loading="tableLoading"
        :data="tableData"
        :max-height="tableMaxHeight"
        :cell-class-name="tableRowClassName"
        border
        disable-transitions
        highlight-current-row
        @sort-change="handleSortChange"
        @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="50" header-align="center" align="center"/>
        <el-table-column label="客户信息" min-width="240" header-align="center">
          <template slot-scope="scope">
            <div>公司名称：{{ scope.row.company || '--' }}</div>
            <div>客户昵称：{{ scope.row.name || '--' }}</div>
            <div>客户姓名：{{ scope.row.realname || '--' }}</div>
            <div>腾讯云ID：{{ scope.row.qq || '--' }}</div>
          </template>
        </el-table-column>
        <el-table-column label="联系方式" min-width="160" header-align="center">
          <template slot-scope="scope">
            <div>手机：{{ scope.row.mobile || '--' }}</div>
            <div>微信：{{ scope.row.wechat || '--' }}</div>
            <div>QQ：{{ scope.row.tencent_id || '--' }}</div>
            <div>邮箱：{{ scope.row.email || '--' }}</div>
          </template>
        </el-table-column>
        <el-table-column label="分配情况" min-width="160" header-align="center">
          <template slot-scope="scope">
            <div><el-tag>{{ scope.row.progress }}</el-tag></div>
            <div>被指派人：{{ scope.row['admin_name'] || '--' }}</div>
            <div>协作者：
              <el-tooltip :content="scope.row.followList" effect="dark" placement="top">
                <span style="white-space: nowrap;overflow: hidden;text-overflow:ellipsis;">{{ scope.row.followList || '--' }}</span>
              </el-tooltip>
            </div>
            <div>上传者：{{ scope.row.addperson || '--' }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="source_time" label="来源动态信息" min-width="300" header-align="center" sortable>
          <template slot-scope="scope">
            <p v-for="(item, index) in scope.row.sources" :key="index">{{ index===scope.row.sources.length-1 ? '初始' : '重复' }}来源：{{ item.create_time }} {{ item.content }}</p>
          </template>
        </el-table-column>
        <el-table-column prop="updated_at" label="跟进状态信息" min-width="300" header-align="center" sortable>
          <template slot-scope="scope">
            <div v-if="scope.row.group.length>0">分组：<el-tag v-for="tag in scope.row.group" :key="tag.id" size="mini" effect="dark" closable style="margin-left: 5px;" @close="handleClose(tag, scope.row.id)">{{ tag.name }}</el-tag></div>
            <div>
              <el-tag :type="scope.row['contact_next_times'].indexOf('逾期')>=0?'danger':scope.row['contact_next_times'].indexOf('年')>=0?'info':scope.row['contact_next_times'].indexOf('月')>=0?'warning':scope.row['contact_next_times'].indexOf('已成交')>=0?'success':''">{{ scope.row['contact_next_times'] }}</el-tag>
              <el-tag>更新时间：{{ scope.row['updated_at'] || '--' }}</el-tag>
            </div>
            <div><el-tag>已跟进{{ scope.row['assign_time'] }}天</el-tag><el-tag v-if="scope.row['contact_next_time']">下次联系：{{ scope.row['contact_next_time'] }}</el-tag></div>
            <div v-if="scope.row['communicate_log']">沟通记录：{{ scope.row['communicate_log'] }}</div>
          </template>
        </el-table-column>
        <el-table-column label="备注信息" min-width="240" header-align="center" align="center">
          <template slot-scope="scope">
            {{ scope.row.remarks || '--' }}
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="120" header-align="center" align="center" fixed="right">
          <template slot-scope="scope">
            <el-tooltip content="沟通" placement="top">
              <el-button v-if="queryMatch(81)" type="success" size="small" icon="el-icon-service" class="bg-green" circle style="margin: 0 10px 0 0;" @click="toRecord(scope.row)"/>
            </el-tooltip>
            <el-tooltip content="激活" placement="top">
              <el-button v-if="scope.row.cust_state===0&&queryMatch(81)&&scope.row['is_follow']===1" type="warning" size="small" icon="el-icon-check" circle style="margin: 0 10px 0 0;" @click="toModify('客户激活', scope.row)" />
            </el-tooltip>
            <el-tooltip content="删除" placement="top">
              <el-button v-if="queryMatch(82)&&scope.row['is_follow']===1" type="danger" size="small" icon="el-icon-close" circle style="margin: 3px 10px 0 0;" @click="toDelete(scope.row)"/>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page.sync="currentPage"
        :page-size="pageSize"
        :page-sizes="pageSizes"
        :total="total"
        class="pagination"
        layout="total, sizes, prev, pager, next, jumper"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"/>
    </el-card>

    <el-dialog :visible.sync="dialogVisible" title="客户指派" width="500px" class="dialog" center>
      <div class="content">
        <div class="text">将所选 {{ multipleSelection.length }} 位客户指派至
          <el-radio-group v-model="transfer.where">
            <!--<el-radio :label="0">公海</el-radio>-->
            <el-radio :label="1">销售</el-radio>
          </el-radio-group>
        </div>
        <el-select v-if="transfer.where==1" v-model="transfer.toId" placeholder="请选择指派用户" filterable>
          <el-option v-for="item in recommendList" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible=false">取 消</el-button>
        <el-button :disabled="loading" :loading="loading" type="primary" @click="doTransfer">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogVisible2" title="添加协作者" width="500px" class="dialog" center>
      <div class="content">
        <div class="text">将所选 {{ multipleSelection.length }} 位客户添加至
          <el-radio-group v-model="transfer2.where">
            <!--<el-radio :label="0">公海</el-radio>-->
            <el-radio :label="1">销售</el-radio>
          </el-radio-group>
        </div>
        <el-select v-if="transfer2.where==1" v-model="transfer2.toId" placeholder="请选择协作者" filterable multiple>
          <el-option v-for="item in recommendList" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible2=false">取 消</el-button>
        <el-button :disabled="loading" :loading="loading" type="primary" @click="doTransfer2">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogVisible3" title="加入分组" width="500px" class="dialog" center>
      <div class="content">
        <div class="text">将所选 {{ multipleSelection.length }} 位客户加入分组</div>
        <el-select v-model="toGroupId" placeholder="请选择分组" filterable>
          <el-option v-for="item in groupList" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibl3=false">取 消</el-button>
        <el-button :disabled="loading" :loading="loading" type="primary" @click="pushToGroup">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { handleSortChange, handleSizeChange, handleCurrentChange, parseTime, dateJudge } from '@/utils/table';
import { fileToBase64 } from '@/utils/index';

export default {
  data() {
    return {
      isShow: false,
      loading: false,
      ImageUrl: '',
      modelUrl: this.$store.getters.serverUrl + '/admin/customer/export?action=demo&token=' + this.$store.getters.token,
      searchTerms: {
        source: '',
        cust_state: '',
        recommend: '',
        progress: '',
        date1: [],
        date2: [],
        searchKey: 'mobile',
        searchValue: '',
        contact_status: '',
        repeatId: '',
        group_id: ''
      },
      downloadLoading: false,
      uploadLoading: false,

      sourceList: [], // 来源列表
      recommendList: [], // 指派人列表
      allMemberList: [], // 所有人员列表
      progressList: ['初步沟通', '需求分析', '展示引导', '方案报价', '协商议价', '成单签约', '丢单'], // 跟进状态列表

      dialogVisible: false,
      transfer: {
        id: '',
        where: 0,
        toId: ''
      },

      dialogVisible2: false,
      transfer2: {
        id: '',
        where: 0,
        toId: ''
      },

      dialogVisible3: false,
      groupList: [],
      inputVisible: false,
      inputValue: '',
      toGroupId: '',

      // 表格相关数据
      tableMaxHeight: document.documentElement.clientHeight - 400,
      multipleSelection: [],
      tableLoading: false,
      currentPage: 1,
      pageSize: this.$store.getters.userInfo.pageSize,
      pageSizes: [10, 20, 50, 100, 1000],
      total: 0,
      tableData: []
    }
  },
  watch: {
    $route(to) {
      if (to.name === '客户仓库') {
        this.getData()
        setTimeout(() => {
          this.isShow = true
        }, 300)
      } else {
        this.isShow = false
      }
    }
  },
  created() {
    if (this.$route.name === '客户仓库') {
      this.isShow = true
      this.getData()
      this.getSourceList()
      this.getRecommendList()
      this.getAllMemberList()
      this.getPersonalGroupList()
    }
  },
  methods: {
    handleCurrentChange, handleSizeChange, handleSortChange, parseTime, dateJudge, fileToBase64,
    getData(order) {
      this.tableLoading = true
      order || (order = {})
      const url = 'customer/list'
      const data = {
        page_no: this.currentPage,
        page_size: this.pageSize,
        search: this.searchTerms.searchValue,
        searchKey: this.searchTerms.searchKey,
        source: this.searchTerms.source,
        cust_state: this.searchTerms.cust_state,
        recommend: this.searchTerms.recommend,
        progress: this.searchTerms.progress,
        contact_status: this.searchTerms.contact_status,
        repeatId: this.searchTerms.repeatId,
        group_id: this.searchTerms.group_id
      }
      this.searchTerms.date1 && this.searchTerms.date1.length !== 0 && (data.start_time = this.searchTerms.date1[0] + ' 00:00:00', data.end_time = this.searchTerms.date1[1] + ' 23:59:59')
      this.searchTerms.date2 && this.searchTerms.date2.length !== 0 && (data.next_start_time = this.searchTerms.date2[0] + ' 00:00:00', data.next_end_time = this.searchTerms.date2[1] + ' 23:59:59')
      order.sortName && (data.sortName = order.sortName)
      order.sortOrder && (data.sortOrder = order.sortOrder)
      this.$store.dispatch('GetConnect', { url, data }).then(res => {
        this.tableData = res.data.rows
        if ((typeof this.tableData) === 'object') {
          const arr = []
          for (const key in this.tableData) {
            if (this.tableData.hasOwnProperty(key)) {
              arr.push(this.tableData[key])
            }
          }
          this.tableData = arr
        }
        this.total = res.data.total
        this.tableLoading = false
        this.uploadLoading = false
      }).catch(e => {
        this.tableLoading = false
        this.uploadLoading = false
        this.$message.error(e.msg + ',请刷新或联系管理员')
      })
    },

    tableRowClassName({row, column}) {
      if (column.type === 'selection' && row.contact_next_times === '今天') {
        return 'warning-0';
      } else if (column.type === 'selection' && row.contact_next_times === '1天'){
        return 'warning-1';
      } else if (column.type === 'selection' && row.contact_next_times === '2天'){
        return 'warning-2';
      } else if (column.type === 'selection' && row.contact_next_times === '3天'){
        return 'warning-3';
      }
      return '';
    },

    /**
     *  获取来源列表
     *  接口:'member/source-list'
     */
    getSourceList() {
      const url = 'member/source-list'
      this.$store.dispatch('GetConnect', { url }).then(res => {
        this.sourceList = res.data
      }).catch(e => {
        this.$message.error(e.msg + ',请刷新或联系管理员')
      })
    },

    /**
     *  获取离职用户列表
     *  接口:'user/admin-list'
     */
    getAllMemberList() {
      const url = 'user/admin-list'
      this.$store.dispatch('GetConnect', { url }).then(res => {
        this.allMemberList = res.data.list
      }).catch(e => {
        this.$message.error(e.msg + ',请刷新或联系管理员')
      })
    },

    /**
     *  获取系统用户列表
     *  接口:'user/all-list'
     */
    getRecommendList() {
      const url = 'user/all-list'// 不包含离职人员
      this.$store.dispatch('GetConnect', { url }).then(res => {
        this.recommendList = res.data
      }).catch(e => {
        this.$message.error(e.msg + ',请刷新或联系管理员')
      })
    },

    toTransfer(where) {
      this.dialogVisible = true;
      this.transfer.where = where;
    },
    toTransfer2(where) {
      this.dialogVisible2 = true;
      this.transfer2.where = where;
    },
    doTransfer() {
      if (this.multipleSelection.length === 0) {
        this.$message.error('请选择要转移的客户')
        this.dialogVisible = false
      } else if (this.transfer.toId === '') {
        this.$message.error('请选择要将客户指派给哪个销售')
      } else {
        const url = 'customer/ajax/' + this.transfer.toId
        const data = {
          action: 'batch_assign',
          id: this.transfer.toId,
          list: []
        }
        this.multipleSelection.forEach(item => {
          data.list.push(item.id)
        })
        data.list = data.list.join(',')
        this.loading = true;
        this.$store.dispatch('GetConnect', { url, data }).then(res => {
          this.$message.success(res.msg)
          this.dialogVisible = false
          this.loading = false;
          this.getData()
        }).catch((err) => {
          this.$message.error(err.msg)
          this.loading = false;
        })
      }
    },
    doTransfer2() {
      if (this.multipleSelection.length === 0) {
        this.$message.error('请选择需要协助的客户')
        this.dialogVisible = false
      } else if (this.transfer2.toId === '') {
        this.$message.error('请选择要将客户添加给哪个销售')
      } else {
        const url = 'customer/ajax/add_follow'
        const data = {
          action: 'add_follow',
          id: this.transfer2.toId.join(','),
          list: []
        }
        this.multipleSelection.forEach(item => {
          data.list.push(item.id)
        })
        data.list = data.list.join(',')
        this.loading = true;
        this.$store.dispatch('GetConnect', { url, data }).then(res => {
          this.$message.success(res.msg)
          this.dialogVisible2 = false
          this.loading = false;
          this.getData()
        }).catch((err) => {
          this.$message.error(err.msg)
          this.loading = false;
        })
      }
    },
    toDelete(row) {
      this.$confirm('此操作将删除该客户线索, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const url = 'customer/delete/' + row.id
        this.$store.dispatch('GetConnect', { url }).then(res => {
          this.$message.success(res.msg)
          this.getData()
        }).catch((err) => {
          this.$message.error(err.msg)
        })
      })
    },
    toDeleteMore() {
      if (this.multipleSelection.length === 0) {
        this.$message.error('请选择要删除的客户')
        this.dialogVisible = false
      } else {
        this.$confirm('此操作将删除所选客户线索, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          const url = 'customer/deleteall'
          const data = {
            id: []
          }
          this.multipleSelection.forEach(item => {
            data.id.push(item.id)
          })
          data.id = data.id.join(',')
          this.$store.dispatch('GetConnect', { url, data }).then(res => {
            this.$message.success(res.msg)
            this.getData()
          }).catch((err) => {
            this.$message.error(err.msg)
          })
        })
      }
    },
    toRecord(row) {
      this.isShow = false
      this.$router.push({
        path: '/customer/mine/record',
        query: { id: row.id }
      })
    },
    toModify(title, row) {
      this.isShow = false
      const query = { title: title }
      row && (query.id = row.id)
      this.$router.push({
        path: '/customer/mine/modify',
        query: query
      })
    },

    toSeleteOverdue() {
      this.searchTerms.contact_status = '即将逾期'
      this.getData()
    },

    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row)
        })
      } else {
        this.$refs.multipleTable.clearSelection()
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },

    beforeUpload(file) {
      // const isExcel = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
      // if (!isExcel) {
      //   this.$message.error('导入失败,请检查导入的文件是否是.xlsx或.xls文件')
      // }
      // return isExcel
    },
    uploadFiles(item) {
      this.uploadLoading = true;
      const url = 'customer/ajax/' + this.$store.getters.id;
      this.fileToBase64(item.file).then(res=>{
        const data = {
          action: 'batch_lead_in',
          file: res
        }
        this.$store.dispatch('UploadFile', { url, data }).then((res) => {
          this.$message.success(res.msg)
          this.getData()
        }).catch((res) => {
          this.uploadLoading = false
          this.$message.error(res.msg)
        })
      });
    },
    // 过滤数据, 去除重复
    doClearList() {
      this.searchTerms.repeatId = this.searchTerms.repeatId ? '' : 171;
      this.getData();
    },
    // 导出
    handleDownload() {
      // if (this.multipleSelection.length === 0) {
      //   this.$message.error('请选择要导出的客户')
      // } else {
        this.downloadLoading = true
        let list = []
        this.multipleSelection.forEach(item => {
          list.push(item.id)
        })
        list = '';
        window.open(`${this.$store.getters.serverUrl}/admin/customer/export?action=data&token=${this.$store.getters.token}&list=${list}&mallId=${this.$store.getters.SaaSId}&start_time=${this.searchTerms.date1[0] + ' 00:00:00'}&end_time=${this.searchTerms.date1[1] + ' 23:59:59'}`)
        this.downloadLoading = false
      // }
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => {
        if (j === 'timestamp') {
          return parseTime(v[j])
        } else {
          return v[j]
        }
      }))
    },

    /**
     *  获取个人分组列表
     *  接口:'user/all-list'
     */
    getPersonalGroupList() {
      const url = 'customer/getGroupList'
      this.$store.dispatch('GetConnect', { url }).then(res => {
        this.groupList = res.data
      }).catch(e => {
        this.$message.error(e.msg + ',请刷新或联系管理员')
      })
    },

    handleClose(tag, customerId) {
      this.$confirm('此操作将删除该分组, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (!customerId) {
          this.groupList.splice(this.groupList.indexOf(tag), 1);
        }
        const url = 'customer/delGroup'
        const data = {id: tag.id, list: customerId};
        this.$store.dispatch('GetConnect', {url, data}).then(res => {
          if (!customerId) {
            this.getPersonalGroupList();
          }
          this.getData();
        }).catch(e => {
          this.$message.error(e.msg + ',请刷新或联系管理员')
        })
      })
    },

    showInput() {
      this.inputVisible = true;
      this.$nextTick(_ => {
        this.$refs.saveTagInput.$refs.input.focus();
      });
    },

    // 添加分组
    handleInputConfirm() {
      const inputValue = this.inputValue;
      if (inputValue) {
        const url = 'customer/getAddGroup'
        const data = {name: inputValue};
        this.$store.dispatch('GetConnect', { url, data }).then(res => {
          this.getPersonalGroupList();
        }).catch(e => {
          this.$message.error(e.msg + ',请刷新或联系管理员')
        })
      }
      this.inputVisible = false;
      this.inputValue = '';
    },
    // 加入分组
    pushToGroup() {
      if (this.multipleSelection.length === 0) {
        this.$message.error('请选择客户')
        this.dialogVisible = false
      } else if (!this.toGroupId) {
        this.$message.error('请选择要将客户加入哪个分组')
      } else {
        const url = 'customer/addCustomerGroup'
        const data = {
          group_id: this.toGroupId,
          list: []
        }
        this.multipleSelection.forEach(item => {
          data.list.push(item.id)
        })
        data.list = data.list.join(',')
        this.loading = true;
        this.$store.dispatch('GetConnect', { url, data }).then(res => {
          this.$message.success(res.msg)
          this.dialogVisible3 = false
          this.loading = false;
          this.toGroupId = '';
          this.getData()
        }).catch((err) => {
          this.$message.error(err.msg)
          this.loading = false;
        })
      }
    }
  }
}
</script>
<style>
  .el-table{
    font-size: 12px;
  }
  .el-table .warning-0 {
    background: #F56C6C;
  }
  .el-table .warning-1 {
    background: #F56C6C;
  }
  .el-table .warning-2 {
    background: #F56C6C;
  }
  .el-table .warning-3 {
    background: #F56C6C;
  }
  .tag-box{
    margin-bottom: 10px;
  }
  .tag-box .el-tag + .el-tag {
    margin-left: 10px;
  }
  .button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
  }
  .input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
  }
</style>

<style lang="scss" type="text/scss" scoped>
@import '../../../styles/index.scss';
.box-1 {
  .header {
    .bar {
      line-height: 50px;
    }
    > div {
      @include flex-row(center, flex-start);
      padding: 2px 0;
      flex-wrap: wrap;
      .upload {
        padding: 0 10px;
      }
      .select {
        padding-right: 15px;
        width: 160px;
      }
      .picker {
        margin-right: 15px;
        width: 300px;
      }
      .do-btn {
        @extend .bg-green;
        margin-left: 6px;
      }
      .search-input {
        width: 320px;
      }
    }
  }
}
.dialog {
  .content {
    text-align: center;
    .text {
      padding-bottom: 20px;
      .el-radio-group {
        padding-left: 15px;
      }
    }
  }
}
  .remarks{
    font-size: 12px;
    color: $textGray;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    line-height: 0px;
  }

</style>
